While not mandatory, using the @Override
annotation on compliant methods improves readability by making it explicit that methods are
overridden.
A compliant method either overrides a parent method or implements an interface or abstract method.
Noncompliant code example
class ParentClass {
public boolean doSomething(){/*...*/}
}
class FirstChildClass extends ParentClass {
public boolean doSomething(){/*...*/} // Noncompliant
}
Compliant solution
class ParentClass {
public boolean doSomething(){/*...*/}
}
class FirstChildClass extends ParentClass {
@Override
public boolean doSomething(){/*...*/} // Compliant
}
Exceptions
This rule does not raise issues when overriding methods from Object
(eg: equals()
, hashCode()
,
toString()
, …).